package com.example.widgetcase.slice;

import com.example.widget_lib.bean.CircleBean;
import com.example.widget_lib.widget.progress.circle.CircleView;
import com.example.widget_lib.widget.ring.LegendRingView;
import com.example.widgetcase.ResourceTable;
import com.example.widgetcase.utils.LogUtil;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.utils.Color;

import java.util.ArrayList;

public class LegendRingViewAblilitySlice extends BaseSlice {

    private CircleView circleView;
    private CircleView circleView2;
    private LegendRingView lrv_three;
    private LegendRingView lrv4;
    private LegendRingView lrv5;
    private Button mButton;

    @Override
    public int getChildUIContent() {
        return ResourceTable.Layout_legend_ring_view;
    }

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        circleView = (CircleView) findComponentById(ResourceTable.Id_cir);
        circleView2 = (CircleView) findComponentById(ResourceTable.Id_cir2);
        lrv_three = (LegendRingView) findComponentById(ResourceTable.Id_lrv_three);
        mButton = (Button) findComponentById(ResourceTable.Id_button);
        lrv4 = (LegendRingView) findComponentById(ResourceTable.Id_lrv4);
        lrv5 = (LegendRingView) findComponentById(ResourceTable.Id_lrv5);
        initData();
    }

    private void initData() {

        circleView.setCircleColors(Color.rgb(255, 196, 0), // 黄色
                Color.rgb(101, 226, 175),// 绿色
                Color.rgb(255, 105, 83),
                Color.rgb(88, 181, 250));
        circleView.setCenterStr("风格 样式");
        circleView.setCenterStyle(2);
        circleView.setData(getData(circleView));
        circleView2.setCircleColors(Color.rgb(255, 196, 0), // 黄色
                Color.rgb(101, 226, 175),// 绿色
                Color.rgb(255, 105, 83),
                Color.rgb(88, 181, 250));
        circleView2.setCenterStr("风格");
        circleView2.setCenterStyle(1);
        circleView2.setData(getData(circleView2));

        int valueSum = 60;
        ArrayList<CircleBean> mList = new ArrayList<>();
        CircleBean cb;
        int rvMax = lrv_three.getCircleView().getMax();
        Float startPro = 0f;
        int size = 5;
        for (int i = 0; i < size; i++) { // 计算数值占圆环的比例
            cb = new CircleBean();
            cb.setStartPro(startPro);

            if (i == 0) {
                cb.setEndPro((12f / valueSum) * rvMax);
            } else if (i == 1) {
                cb.setEndPro((24f / valueSum) * rvMax);
            } else if (i == 2) {
                cb.setEndPro((4f / valueSum) * rvMax);
            } else if (i == 3) {
                cb.setEndPro((4f / valueSum) * rvMax);
            } else {
                cb.setEndPro((16f / valueSum) * rvMax);
            }

            cb.setCenterPro(startPro + cb.getEndPro() / 2);
            startPro += cb.getEndPro();
            LogUtil.loge("===========" + cb.getEndPro());
            mList.add(cb);
        }

        ArrayList<String> labels = new ArrayList<>();
        labels.add("项链");
        labels.add("戒指");
        labels.add("男你你");
        labels.add("戒指");
        labels.add("男你拿");
        lrv_three.setData(mList, labels);

        mButton.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                labels.clear();
                labels.add("M趴窝");
                labels.add("AMG");
                labels.add("RS7");
                labels.add("BB");
                labels.add("迪迦");
                lrv_three.setData(mList, labels);
            }
        });

        setLrv4Data();
        setLrv5Data();
//        lrv_three.setImagePic(com.example.widget_lib.ResourceTable.Media_load_more_32);
    }

    public ArrayList<CircleBean> getData(CircleView circleView) {
        int valueSum = 60;
        ArrayList<CircleBean> mList = new ArrayList<>();
        CircleBean cb;
        int rvMax = circleView.getMax();
        Float startPro = 0f;
        int size = 4;
        for (int i = 0; i < size; i++) { // 计算数值占圆环的比例
            cb = new CircleBean();
            cb.setStartPro(startPro);

            if (i == 0) {
                cb.setEndPro((12f / valueSum) * rvMax);
            } else if (i == 1) {
                cb.setEndPro((24f / valueSum) * rvMax);
            } else if (i == 2) {
                cb.setEndPro((8f / valueSum) * rvMax);
            } else {
                cb.setEndPro((16f / valueSum) * rvMax);
            }

            cb.setCenterPro(startPro + cb.getEndPro() / 2);
            startPro += cb.getEndPro();
//            Common.log_d("201811091554", cb.toString())
            LogUtil.loge("===========" + cb.getEndPro());
            mList.add(cb);
        }
        return mList;
    }

    public void setLrv4Data(){
        int valueSum = 60;
        ArrayList<CircleBean> mList = new ArrayList<>();
        CircleBean cb;
        int rvMax = lrv4.getCircleView().getMax();
        Float startPro = 0f;
        int size = 4;
        for (int i = 0; i < size; i++) { // 计算数值占圆环的比例
            cb = new CircleBean();
            cb.setStartPro(startPro);

            if (i == 0) {
                cb.setEndPro((12f / valueSum) * rvMax);
            } else if (i == 1) {
                cb.setEndPro((24f / valueSum) * rvMax);
            } else if (i == 2) {
                cb.setEndPro((8f / valueSum) * rvMax);
            }else {
                cb.setEndPro((16f / valueSum) * rvMax);
            }

            cb.setCenterPro(startPro + cb.getEndPro() / 2);
            startPro += cb.getEndPro();
            LogUtil.loge("===========" + cb.getEndPro());
            mList.add(cb);
        }

        ArrayList<String> labels = new ArrayList<>();
        labels.add("项链");
        labels.add("戒指");
        labels.add("男你你");
        labels.add("戒指");
        lrv4.setCenterStr("看看 测试");
        lrv4.setData(mList, labels);
    }

    public void setLrv5Data(){
        int valueSum = 60;
        ArrayList<CircleBean> mList = new ArrayList<>();
        CircleBean cb;
        int rvMax = lrv5.getCircleView().getMax();
        Float startPro = 0f;
        int size = 3;
        for (int i = 0; i < size; i++) { // 计算数值占圆环的比例
            cb = new CircleBean();
            cb.setStartPro(startPro);

            if (i == 0) {
                cb.setEndPro((16f / valueSum) * rvMax);
            } else if (i == 1) {
                cb.setEndPro((24f / valueSum) * rvMax);
            } else {
                cb.setEndPro((20f / valueSum) * rvMax);
            }

            cb.setCenterPro(startPro + cb.getEndPro() / 2);
            startPro += cb.getEndPro();
            LogUtil.loge("===========" + cb.getEndPro());
            mList.add(cb);
        }

        ArrayList<String> labels = new ArrayList<>();
        labels.add("项链");
        labels.add("戒指");
        labels.add("男你你");
        lrv5.setData(mList, labels);
    }
}
